/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latticeware.xtalk.stack;

import com.latticeware.xtalk.app.LatticeCard;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;



/**
 *
 * @author sfisque
 */
public class AskDialog
extends Dialog
{    
    protected Label promptLabel;
    
    protected TextField askAnswer;
    
    protected java.awt.Button okButton;
    
    protected java.awt.Button cancelButton;
    
    protected boolean cancelled;
    
    protected boolean password;
    
    
    public AskDialog()
    {
        super( LatticeCard.getInstance().getWindow(), null, true );
        
        setUndecorated( true );
        setResizable( false );
        
        Panel p0 = new Panel();
        
        promptLabel = new Label( "What is it?" );
        p0.add( promptLabel );
        
        askAnswer = new TextField( 64 );
        p0.add( askAnswer );
        
        add( p0 );
        
        ButtonListener bl = new ButtonListener();
        
        Panel p1 = new Panel();
        
        okButton = new java.awt.Button( "OK" );
        okButton.addActionListener( bl );
        p1.add( okButton );
        
        cancelButton = new java.awt.Button( "Cancel" );
        cancelButton.addActionListener( bl );
        p1.add( cancelButton );
        
        add( p1, BorderLayout.SOUTH );
    }


    public String getPrompt()
    {
        return promptLabel.getText();
    }


    public void setPrompt(String prompt)
    {
        promptLabel.setText( prompt );
    }
    

    public String getAnswer()
    {
        return askAnswer.getText();
    }


    public boolean isCancelled()
    {
        return cancelled;
    }


    public void setCancelled(boolean cancelled)
    {
        this.cancelled = cancelled;
    }


    public void setAnswer(String deftext)
    {
        askAnswer.setText( deftext );
    }


    public boolean isPassword()
    {
        return password;
    }


    public void setPassword(boolean password)
    {
        this.password = password;
        
        if( password )
        {
            askAnswer.setEchoChar( '#' );
        }
        else
        {
            askAnswer.setEchoChar( (char) 0 );
        }
    }
    
    
    class ButtonListener
    implements ActionListener
    {
        @Override
        public void actionPerformed( ActionEvent e )
        {
            AskDialog.this.cancelled = e.getSource() == AskDialog.this.okButton;
            
            AskDialog.this.setVisible( false );
        }
        
    }
}
